back to Creeper World
# Immortal-Nest.crpl
# Created by: nathanaelps
# Created on: 8/28/2020 12:04:36 PM
# ------------------------------------------

$RunnerCount:2
$RunnerDelay:1 #seconds
$RunnerSpeed:1
$RunnerHealthMin:1
$RunnerHealthMax:5
$RunnerBleedoutMin:-100
$RunnerBleedoutMax:100

$IsFlipped:0
$capturedSecondsAtFullCapacity:10

once @initialize endonce

<-IsFlipped not if
  @checkForFlip
else
  <-IsDead if
    Self CONST_AMMO Self CONST_AMMO GetUnitAttribute 1 sub SetUnitAttribute
    @shouldWeRaise
  else
    @shouldWeKill
  endif
endif

<-IsDead not
0 <-RunnerDelay 3 mul RandInt 1 eq and if @makeARunner endif

10 delay

#-------------------------------

:checkForFlip
  Self CONST_HEALTH GetUnitAttribute Self CONST_MAXHEALTH GetUnitAttribute neq if
    @setIsFlipped
  endif


:shouldWeRaise
  Self CONST_AMMO GetUnitAttribute ->AmmoPool

  <-AmmoPool 0 lte if
    @setLive
  endif

:shouldWeKill
  Self CONST_AMMO GetUnitAttribute ->AmmoPool

  <-IsFlipped <-AmmoPool 0 gt and if
    #freshly recieved ammo
    @setDead
  endif

:makeARunner
  GetRunnerCount <-RunnerCount lt CurrentCoords GetDigitalis 0 gt and if
    CurrentCoords <-RunnerSpeed # -->
      <-RunnerHealthMin <-RunnerHealthMax RandInt # -->
      <-RunnerBleedoutMin <-RunnerBleedoutMax RandInt # -->
      CreateRunner
  endif

:setDead
  "BLUE" "INFO" "Nest quelled" "" CurrentPixelCoords ShowGameEventTag
  1 ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
  Self CONST_SUPPORTSDIGITALIS 0 SetUnitAttribute

:setLive
  "RED" "INFO" "Nest awake" "Power to quell" CurrentPixelCoords ShowGameEventTag
  0 ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY 1 SetUnitAttribute
  Self CONST_SUPPORTSDIGITALIS 1 SetUnitAttribute

:setIsFlipped
  1 ->IsFlipped
  Self CONST_AMMO 0 SetUnitAttribute
  Self CONST_CONNECTABLE 1 SetUnitAttribute
  Self CONST_REQUESTPACKETS 1 SetUnitAttribute
  Self CONST_SHOWAMMOBAR 1 SetUnitAttribute
  Self CONST_CANREQUESTAMMO 1 SetUnitAttribute
  Self CONST_PACKETREQUESTDELAY 1 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
  @setLive
  #@updateImage #already done when we setLive

:initialize
  #ShowTraceLog
  @setLive
  @setNestName
  Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
  Self CONST_CONNECTABLE 0 SetUnitAttribute
  Self CONST_CREATEPZ 0 SetUnitAttribute
  Self CONST_SHOWAMMOBAR 0 SetUnitAttribute
  Self CONST_MAXAMMO <-capturedSecondsAtFullCapacity 3.0 mul SetUnitAttribute
  Self CONST_CANREQUESTAMMO 0 SetUnitAttribute
  Self CONST_REQUESTPACKETS 0 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGES 1 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGEAMT 0.1 SetUnitAttribute
  Self CONST_SUPPORTSDIGITALIS 1 SetUnitAttribute
  @updateImage
  ->IsFlipped if @setIsFlipped endif

:updateImage
  32 ->ImageStartID
  Self "main" 1.3 1.3 SetImageScale
  <-IsFlipped if
    <-IsDead if
      Self "main" "Custom" <-ImageStartID 3 add Concat SetImage
    else
      Self "main" "Custom" <-ImageStartID 2 add Concat SetImage
    endif
  else
    <-IsDead if
      Self "main" "Custom" <-ImageStartID 1 add Concat SetImage
    else
      Self "main" "Custom" <-ImageStartID 0 add Concat SetImage
    endif
  endif

:setNestName
  <-RunnerCount " max runners, produce every " <-RunnerDelay "s" Concat Concat Concat SetPopupText